import {cfg} from "./config";
import {login} from "./login";

class MyRequest {
    public async post(path: string, body?: any) {
        console.log(`${cfg.server}/${path}`)
        const res = await fetch(`${cfg.server}/${path}`, {
            method: 'POST',
            headers: {
                cookie: await login.getCookie(),
            },
            body: body,
        });

        if (!res.ok) {
            throw new Error(res.statusText)
        }
        const data = await res.json()
        if (data.state !== 0) {
            throw new Error(JSON.stringify(data))
        }
        console.log("req response", data)
        return data.data;
    }
}
export const req = new MyRequest();
